﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Model;
using BLL;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json;
using System.Data;
using System.Web.Routing;
using System.Web.Http.WebHost;
using System.Web.SessionState;
using System.Web;

namespace WebApplication1.Controllers
{
    public class ValuesController : ApiController
    {
        users_bll usersbll = new users_bll();
        /// <summary>
        /// 测试用方法
        /// </summary>
        /// <returns></returns>
        /// 
        [HttpGet]
        public string getAAA()
        {
            List<Firm> li = new BLL.FirmBLL().CeShi();
            string a = JsonConvert.SerializeObject(li);
            return a;
        }

        [HttpGet]
        /// <summary>
        /// 分页显示面试经验信息条件公司
        /// </summary>
        /// <param name="pageindex"></param>
        /// <param name="pagesize"></param>
        /// <param name="Firm_Name"></param>
        /// <returns></returns>
        public string GetPageShow(int pageindex, int pagesize, string Login_Nickname)
        {
            QinterviewBLL bll = new QinterviewBLL();
            string list = JsonConvert.SerializeObject(bll.PageShow(pageindex, pagesize, Login_Nickname), new DataSetConverter());
            return list;
        }

        /// <summary>
        /// 带条件分页获取获取面试经验文章
        /// </summary>
        /// <param name="pageindex"></param>
        /// <param name="pagesize"></param>
        /// <param name="UserId"></param>
        /// <returns></returns>
       [HttpGet]
        public string GetArticlescrap(int pageindex, int pagesize, int UserId)
        {
            ArticlescrapBLL bll = new ArticlescrapBLL();
            pageLibrary<Articlescrap> list = bll.GetArticlescrap(pageindex, pagesize, UserId);
             string result = JsonConvert.SerializeObject(list);
            return result;
        }
        /// <summary>
        /// 根据Id获取面试经验文章信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public string GetArtById(int id)
        {
            ArticlescrapBLL bll = new ArticlescrapBLL();
            List<Articlescrap> list = bll.GetArtById(id);
            string result = JsonConvert.SerializeObject(list);
            return result;
        }

         /// <summary>
        /// 根据Id删除面试经验文章
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
       public int DelArticlescrap(int id)
       { 
            ArticlescrapBLL bll = new ArticlescrapBLL();
           if (bll.DelArticlescrap(id) == 1)
           {
               return 1;
           }
           else
           {
               return 0;
           }
       }

        /// <summary>
       /// 获取所有用户
       /// </summary>
       /// <returns></returns>
       public string GetUsers()
       {
           users_bll bll = new users_bll();
           string result = JsonConvert.SerializeObject(bll.GetUsers());
            return result;
        }
        /// <summary>
        /// 前台用户登录
        /// </summary>
        /// <returns></returns>
         [HttpGet]
        public List<users> getjsonLogin(string Login_Name, string Login_Pwd)
        {
            List<users> list = usersbll.Login(Login_Name, Login_Pwd);
           
            if (list != null && list.Count > 0)
            {
                return list;
            }
            else
            {
                return null;
            }


        }
        [HttpGet]
        /// <summary>
        /// 后台登录
        /// </summary>
        /// <param name="Name"></param>
        /// <param name="Pwd"></param>
        /// <returns></returns>
        public string GetLogin(string name, string pwd)
        {
            LoginBLL bll = new LoginBLL();
            string Json = JsonConvert.SerializeObject(bll.Login(name, pwd));
            return Json;
        }

        /// <summary>
        /// 绑定职位下拉框
        /// </summary>
        /// <returns></returns>
        public string GetDropPos()
        {
            var PositionDrop = new BLL.AddInterviewBLL().DropPosition();
            string result = JsonConvert.SerializeObject(PositionDrop);
            return result;
        }
        /// <summary>
        /// 删除评论信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int DelRated(int id)
        {
            RatedBLL bll = new RatedBLL();
            if (bll.DelRated(id) == 1)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        /// <summary>
        /// 显示评论信息
        /// </summary>
        /// <param name="pageindex"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        [HttpGet]
        public string ShowRated(int pageindex, int pagesize, string Ratedname)
        {
            RatedBLL bll = new RatedBLL();
            string result = JsonConvert.SerializeObject(bll.ShowRated(pageindex, pagesize, Ratedname));
            return result;
        }

        /// <summary>
        /// 面试表显示数据
        /// </summary>
        /// <returns></returns>
      [HttpGet]
        public string GetInter(int pageindex, int pagesize, string interview_data)
        {
            InterviewBLL bll = new InterviewBLL();
            pageLibrary<Interview> list = bll.GetInter(pageindex, pagesize, interview_data);
            string result = JsonConvert.SerializeObject(list);
            return result;
        }
      
        /// <summary>
        /// 面试表添加数据
        /// </summary>
        /// <param name="m">面试表</param>
        /// <returns></returns>
        public int SetInter(Interview Interview)
        {
            InterviewBLL bll = new InterviewBLL();
            if (bll.SetInter(Interview) == 1)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        [HttpGet]
        /// <summary>
        /// 面试表删除数据
        /// </summary>
        /// <param name="m">面试表ID</param>
        /// <returns></returns>
        public int DelInter(int id)
        {
            InterviewBLL bll = new InterviewBLL();
            if (bll.DelInter(id) >0)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        /// <summary>
        /// 根据ID显示数据
        /// </summary>
        /// <returns></returns>
        public string GetInterUpdate(int id)
        {
            InterviewBLL bll = new InterviewBLL();
            string result = JsonConvert.SerializeObject(bll.GetInterUpdate(id));
            return result;
        }
        /// <summary>
        /// 面试表修改数据
        /// </summary>
        /// <param name="m">面试表</param>
        /// <returns></returns>
        public int SetInterUpdate(Interview Interview)
        {
            InterviewBLL bll = new InterviewBLL();
            if (bll.SetInterUpdate(Interview) == 1)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        /// <summary>
        /// 删除职位信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int DelPosition(int id)
        {
            PositionBLL bll = new PositionBLL();
            if (bll.DelPosition(id) == 1)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        /// <summary>
        /// 显示职位信息
        /// </summary>
        /// <param name="pageindex"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        [HttpGet]
        public string ShowPosition(int pageindex, int pagesize)
        {
            PositionBLL bll = new PositionBLL();
            string result = JsonConvert.SerializeObject(bll.ShowPosition(pageindex, pagesize));
            return result;
        }
        /// <summary>
        /// 添加面试经验文章
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int addinfo(Articlescrap artic)
        {
            artic.Articlescrap_date = DateTime.Now;

            ArticlescrapBLL bll = new ArticlescrapBLL();
            if (bll.addinfo(artic) > 0)
            {

                return 1;
            }
            else
            {
                return 0;
            }
        }

        public string GetShowInterviewInfo(int id)
        {
            string result = JsonConvert.SerializeObject(new BLL.AddInterviewBLL().ShowInterview(id));
            return result;
        }
        /// <summary>
        /// 获取我发布的面试试题
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public string GetTEst(int pageindex, int pagesize, int users_id)
        {
            //实例化对象
            QinterviewBLL bll = new QinterviewBLL();
            Pager<Interview> list = bll.PageShowTest(pageindex, pagesize, users_id);
            string Json = JsonConvert.SerializeObject(list, new DataSetConverter());
            return Json;
        }
    }
}
